c

Packet manipulation library in C

Hi all, I am playing with libnetfilter_queue and am looking for a good C library to work with packets captured by libnetfilter_queue. I really like the dpkt library for python and some similar library for C would be wonderful. Any other workaround or example code for manipulating the packets are also welcome. with regards, raj ...

Invalid read of size 8 - Valgrind + C

Valgrind reports error Invalid read of size 8 in the following code. I have an array declared like, struct symbol *st[PARSER_HASH_SIZE]; When my program is initialized, all the elements in this array are initailzied as 0. memset(&st[0], 0, sizeof(st)); My program creates instances of struct symbol and inserts into the above arra...

Converting a C (\0 terminated) string to a PHP string

PHP is one of those languages I use periodically, but usually have to dust the cobwebs off when I start using it again. The same applies this week whilst I port some C code to PHP. This uses a lot of AES encryption and SHA256 hashing - all working fine so far. However, decrypted strings come out in "C" form - i.e. terminated with a zero ...

C socket server, Java socket client : BLOCKING!!

Dear All, I am pasting my code for a simple socket server in C and a java client. I use write method sending character by character in Java. However after the chunk of characters are sent(here, 'h', 'e', 'y') , the Java client is send blocked as the C server does not reply to it :( I am assuming there is some problem with sending a nu...

Sources from subdirectories in Makefile

I have a C++ library built using a Makefile. Until recently, all the sources were in a single directory, and the Makefile did something like this SOURCES = $(wildcard *.cpp) which worked fine. Now I've added some sources that are in a subdirectory, say subdir. I know I can do this SOURCES = $(wildcard *.cpp) $(wildcard subdir/*.cpp) ...

Projectile curve using GDI

I've calculated the range of projection with given angle, height and velocity. How can you draw a projection curve of that using GDI? ...

Is there a way to prevent sh/bash from performing command substitution?

From a C program I want to call a shell script with a filename as a parameter. Users can control the filename. The C is something like (initialization/error checking omitted): sprintf(buf, "/bin/sh script.sh \"%s\"", filename); system(buf); The target device is actually an embedded system so I don't need to worry about malicious use...

Possible to define a function-like macro with a variable body?

I've been looking at the GCC docs for defining macros and it looks like what I want isn't possible, but I figure if it is, someone here would know. What I want to do is define this macro: synchronized(x) { do_thing(); } Which expands to: { pthread_mutex_lock(&x); do_thing(); pthread_mutex_unlock(&x); } In C++ I could...

When opening a file in append mode, how can I reposition the file pointer?

I am trying to insert some data into the middle of a file. I have opened the file in append mode as: file = fopen(msg->header.filename, "ab"); I then tried a seek to the desired offset in the file as so: fseek(file, msg->header.offset, SEEK_SET); However, when I then try an fwrite as so: int bytesWritten = fwrite(msg->message, 1, ...

Why multiple definitions? Why are other references not defined? This is really basic, what am I missing?

I have a small project that I need to compile. I have one header and one source that I have created and a nearly empty driver.c that includes my header. Observe: // iol.h #ifndef __IOL_HEADER #define __IOL_HEADER /* program: iol.h date: 5 October 2010 */ #define UNIX 1 #define WINDOWS 2 #define OS UNIX #if OS == UNIX #...

Replace a string in a macro variable?

I have a macro where I pass in an argument and use that define a new variable based on the name of the input: #define DO_X(x) char _do_x_var_ ## x; /* other things */ The problem is if I pass in a struct variable, it breaks: DO_X(some_struct->thing) becomes: char _do_x_var_some_struct->thing; /* other things */ EDIT: What I want...

Possible to convert an address assignment to function argument via C macro?

I am working on embedded code and attempting to convert a lot of memory-mapped register assignments to get()/set() function calls. I was wondering if it would be possible to maintain the address assignments sprinkled throughout the code, but change the #defines so they take the assignment in as a function argument. Old Way: #define MOT...

possible to retrieve time left on a glib 'event?'

I am creating an event with g_timeout_add or g_timeout_add_seconds which returns an event id; I can cancel the event by calling g_source_remove. However, at some point what I would like to do is see how much time is remaining until the event is fired. Is there a simple way to do this with the glib api, or do I need to manually store an...

Why am i getting "warning: assignment from incompatible pointer type"? Double linked list in a struct array

Hi, I'm trying to make an implementation of a double linked list which connects to an array. The struct that makes the array contains the list's Head and Tail pointer. typedef struct myStruct{ int code; struct myStruct *Head; struct myStruct *Tail; }myStruct; myStruct MyArray[10]; Here's my double linked list: struct myList { ...

How to put a C function in some address range.

I am developing a USB based bootloader for HCS08 family of micro-controllers. I have the bootloader code in assembly(which works fine for serial communication). I am calling a C functions for USB communication (Terminal<>Micro controller) from this assembly code. However, it seems that these C functions are not getting located in protec...

Help setting up Eclipse for Remote C Debugging !

Hi ! I am pretty new to Eclipse. Trying to set up to do remote debugging. Here is situation, I am connecting to remote machine running Linux, I am running Windows. 1) I have installed all the necessary tool for Eclipse, and was able to connect to Linux machine. 2) Remote machine has gdbserver linux1[1]% gdbserver Usage: gdbserver [OP...

Small C Projects

I am a professional developer who generally uses high level, memory managed languages. However, I am growing more and more ashamed at my incompetence at low level languages like C, which I haven't used since my Systems courses in college. I want to relearn some of the more distinct parts of the C language, but I don't have a large amoun...

Deleting a line from a file, reading and rewriting is very inefficient ... can someone come up with a better algorithm?

Hi, Deleting a particular line/certain bytes from a file is very inefficient as there is a lot of reading and writing(re-writing) to be done. Is there anyway we can minimize work in such a process? Imagine if an entire file is a set of linked lists and as a user we know the structure of these linked lists then wouldn't it be wonderful a...

Was there a specific reason garbage collection was not designed for C?

I have heard that it was suboptimal for C to automatically collect garbage -- is there any truth to this? Was there a specific reason garbage collection was not implemented for C? ...

Performing a logical not ! using only bitwise operations.

Possible Duplicate: Check if a number is non zero using bitwise operators in C. Hello everyone, I am working on a project and I need a little help with a function. We need to write a function that performs the logical not, !, using only the following bitwise operators: ~ & ^ | + << >> I'm not even sure where to begin. ...