Skip to contentSkip to conversation

Parsing multipart MIME

DISCUSSION Darío Mariani 3 participants 3 messages Aug 15, 2003 – Aug 20, 2003

lore
Share & tools
lore
#0 lore raw

Hello:
I'm building a minimal MIME parser, mainly to separate the parts in a
multipart/form-data in a web POST. I was wondering if anyone made the regular expression for interpreting it. I thought of this:

multip ::= start anychar* (delim anychar*)* end?

anychar ::= <any character including \0>

delim   ::= <delimiter>
start   ::= "--" delim "\r\n"
middle  ::= "\r\n--" delim "\r\n"
end     ::= "\r\n--" delim "--"

I have little experience with grammars so this expression may be
wrong. Any ideas? thanks,

Darío

-
To unsubscribe from this list: send the line "unsubscribe linux-c-programming" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

#1 lore raw

SEGFAULT

I can't figure out why this code sigfaults when it exits.
gdb only tells me

Program received signal SIGSEGV
0xda64a8c0 in ? ()

and shows the step as being the final "}" in main ().
as far as I can tell this means either one of the linux libraries is wrong or my code is doing something funny with a buffer.
I'll gladly e-mail a dollar to anyone who can tell me what is wrong with this short bit of code. Well, I mean what is wrong that causes the SIGSEGV.

_________________CODE______________________

#include <sys/types.h>
#include <sys/socket.h>
#include <sys/wait.h>
#include <netinet/in.h>
#include <unistd.h>
#include <netdb.h>

#define HOST_NAME_MAX 255

int main( ) {
int loop;
struct sockaddr_in *active;
struct sockaddr_in passive;
struct hostent *host;
struct protoent *proto;
int port, activeLen, newSkt, skt;
char HOSTNAME[HOST_NAME_MAX];
int hostnamelength;
int pid;

host = NULL;

proto = getprotobyname("tcp");

if( ( skt = socket(PF_INET, SOCK_STREAM, proto->p_proto ) ) == -1 ) {
printf("Cannot create socket\n");
exit(1);
}

if(gethostname(HOSTNAME, hostnamelength) ) {
printf("fuck\n");
exit(1);

}

host = gethostbyname(HOSTNAME);

passive.sin_family = host->h_addrtype; passive.sin_port = htons( 4023 ); bcopy(host->h_addr, &passive.sin_addr, host->h_length);

if(bind(skt, (struct sockaddr *) &passive, sizeof(passive) ) ) {
printf("bind failed\n");
exit(1);
}

if( listen(skt, 10) ) {
printf("listen failed\n");
close(skt);
exit(1);
}

activeLen = sizeof(active);

for(loop=0;loop<2;loop++) {

  newSkt = accept(skt, (struct sockaddr *) active, &activeLen);

  if( (pid = fork() ) == 0 ) {
   close(skt);
   printf("connection accepted\n");
   fflush(NULL);
   close(newSkt);
   _exit(0);

} else close(newSkt);
}

wait(NULL);
sleep(1);

close(skt);

return 0;
}
_______________________END CODE________________

#2 lore raw

Re: SEGFAULT

Quoted 7 lines · John T. Williams

I can't figure out why this code sigfaults when it exits.
gdb only tells me

Program received signal SIGSEGV
0xda64a8c0 in ? ()

and shows the step as being the final "}" in main ().

Sandro has already pointed out some likely causes of the segfault.

However, the above GDB output suggests that you compiled the program either without debug info (without -g), or without a frame pointer (with -fomit-frame-pointer), or that you subsequently stripped the debug info (e.g. with the -s linker switch).

If you want to be able to debug a program, use the -g switch for both compilation and linking, and don't use any optimisation switches.

Signature · 1 line
Glynn Clements <[email protected]>