linux-c-programming.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* Parsing multipart MIME
@ 2003-08-15 18:05 Darío Mariani
  2003-08-20 18:56 ` SEGFAULT John T. Williams
  0 siblings, 1 reply; 4+ messages in thread
From: Darío Mariani @ 2003-08-15 18:05 UTC (permalink / raw)
  To: linux-c-programming

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 majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

^ permalink raw reply	[flat|nested] 4+ messages in thread
* RE: SEGFAULT
@ 2003-08-20 19:21 Sandro Dangui
  0 siblings, 0 replies; 4+ messages in thread
From: Sandro Dangui @ 2003-08-20 19:21 UTC (permalink / raw)
  To: John T. Williams, linux-c-programming


I can see two mistakes:

First, you have to initialize hostnamelength = sizeof(HOSTNAME);

Second, accept() doesn't alloc memory to return data in sockaddr_in*;
Then, you must define "active" variable like this: struct sockaddr_in
active;
And call: accept(skt, (struct sockaddr *) &active, &activeLen);




-----Original Message-----
From: John T. Williams [mailto:jtwilliams@vt.edu] 
Sent: quarta-feira, 20 de agosto de 2003 15:56
To: linux-c-programming@vger.kernel.org
Subject: 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________________

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

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2003-08-20 19:35 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2003-08-15 18:05 Parsing multipart MIME Darío Mariani
2003-08-20 18:56 ` SEGFAULT John T. Williams
2003-08-20 19:35   ` SEGFAULT Glynn Clements
  -- strict thread matches above, loose matches on Subject: below --
2003-08-20 19:21 SEGFAULT Sandro Dangui

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).