[Assorted-commits] SF.net SVN: assorted: [663] sandbox/trunk/src/c/stsegfaultbug.c
Brought to you by:
yangzhang
From: <yan...@us...> - 2008-04-20 03:02:36
|
Revision: 663 http://assorted.svn.sourceforge.net/assorted/?rev=663&view=rev Author: yangzhang Date: 2008-04-19 20:02:37 -0700 (Sat, 19 Apr 2008) Log Message: ----------- added st segfault "bug" Added Paths: ----------- sandbox/trunk/src/c/stsegfaultbug.c Added: sandbox/trunk/src/c/stsegfaultbug.c =================================================================== --- sandbox/trunk/src/c/stsegfaultbug.c (rev 0) +++ sandbox/trunk/src/c/stsegfaultbug.c 2008-04-20 03:02:37 UTC (rev 663) @@ -0,0 +1,50 @@ +// Not really a bug...see the end! + +#include <arpa/inet.h> +#include <netdb.h> +#include <netinet/in.h> +#include <strings.h> +#include <sys/socket.h> +#include <unistd.h> + +#include <st.h> + +int +main() +{ + int sfd = socket(PF_INET, SOCK_STREAM, 0); + + // Create the socket address. + struct sockaddr_in sa; + bzero(&sa, sizeof(sa)); + sa.sin_family = AF_INET; + sa.sin_port = htons(17000); + sa.sin_addr.s_addr = htonl(INADDR_ANY); + + // Configure the socket. + int n = 1; + if (setsockopt(sfd, SOL_SOCKET, SO_REUSEADDR, (char *)&n, sizeof(n)) != 0) { + perror("setsockopt"); + return 1; + } + + // Bind the socket to the local socket address. + if (bind(sfd, (struct sockaddr*) &sa, sizeof(struct sockaddr_in)) != 0) { + perror("bind"); + return 1; + } + + // Start listening. + if (listen(sfd, 256)) { + perror("listen"); + return 1; + } + + st_init(); + + // I thought there was a segfault bug here, but it was because I had + // forgotten to initially call st_init(). + st_netfd_t nfd = st_netfd_open_socket(sfd); + + return 0; +} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |