![]() |
| | #1 | |
| Registered User Join Date: Sep 2004
Posts: 17
| Problems with sockets under linux Code: #include "../unp.h"
#include <time.h>
int main(int argc, char **argv)
{
int listenfd, connfd;
struct sockaddr_in servaddr;
char buff[MAXLINE];
time_t ticks;
listenfd = Socket(AF_INET, SOCK_STREAM, 0);
bzero(&servaddr, sizeof(servaddr));
servaddr.sin_family = AF_INET; bzero(&servaddr, sizeof(servaddr));
servaddr.sin_family = AF_INET;
servaddr.sin_addr.s_addr = hton1(INADDR_ANY);
servaddr.sin_port = htons(13);
Bind(listenfd, (SA *) &servaddr, sizeof(servaddr));
Listen(listenfd, LISTENQ);
for (;;)
{
connfd = Accept (listenfd, (SA *) NULL, NULL);
ticks = time(NULL);
snprintf(buff, sizeof(buff), "%.24s\r\n", ctime(&ticks));
Write(connfd, buff, strlen(buff));
Close(connfd);
}
}
Quote:
Last edited by principii; 09-17-2004 at 03:23 PM. Reason: editing topic - said it wrong | |
| principii is offline | |
| | #2 |
| Registered User Join Date: Mar 2003 Location: Louisiana
Posts: 926
| Something is wrong withy your headers, your ../unp.h is including files that don't exist. You are also somewhere including a header that trying to define functions already included. Check your headers. |
| linuxdude is offline | |
| | #3 |
| Registered User Join Date: Jul 2003
Posts: 85
| or, only include what's needed... check man or your book (i'm assuming unix net prog)
__________________ Free iPod?! |
| scrappy is offline | |
| | #4 |
| Registered User Join Date: Sep 2004
Posts: 17
| scrappy - I downloaded the source code for all of the programs included with unix net prog, and took unp.h from it (i didn't want to type it up myself), stuck it in a directory with subdirectories Server and Client each containing the two programs specified in chapter one of unix net prog. |
| principii is offline | |
| | #5 | |
| Crazy Fool Join Date: Jan 2003 Location: Canada
Posts: 2,596
| Quote:
if you want to learn socket prgramming i suggest taking a look at Beej's Guide . Its more or less the bible of learning socket programmming under unix.
__________________ jeff.bagu.org - Terrain rendering and other random stuff | |
| Perspective is offline | |
| | #6 |
| Registered User Join Date: Sep 2004
Posts: 17
| I figured it out. I had to use autoconf. |
| principii is offline | |
![]() |
| Thread Tools | |
| Display Modes | |
|
Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Linux problems | Dark_Phoenix | Tech Board | 1 | 03-22-2008 05:30 AM |
| HPUX sockets vs Linux? | cpjust | Linux Programming | 4 | 12-06-2007 02:51 PM |
| Segfault with C sockets on Linux | arti_valekar | C Programming | 3 | 02-16-2005 02:25 AM |
| Linux To FreeBSD Porting Compile Problems | DeepBlackMagic | Linux Programming | 4 | 03-17-2004 08:17 AM |
| Red Hat Linux 8.0 Loading Failure? + Many other Problems! | jawwadalam | Tech Board | 3 | 10-29-2003 09:39 AM |