delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1999/02/05/10:25:35

From: Edward Hill <edward_hill AT ns2 DOT downtown DOT com>
Newsgroups: comp.os.msdos.djgpp
Subject: rsxntdj and sockets
Date: Fri, 05 Feb 1999 14:55:03 -0800
Organization: Easams Engineering Systems
Lines: 62
Message-ID: <36BB76C7.7AD4@gec.nospam.com>
NNTP-Posting-Host: pc02372.gmsws.gecm.com
Mime-Version: 1.0
X-Mailer: Mozilla 3.01C-GECMMTL (Win95; I; 16bit)
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp
Reply-To: djgpp AT delorie DOT com

It made me happy to see a sockets.h 
in the include/sys directoy when I installed 
rsxntdj, I have been trying to get a simple
server up and running but alas it seg faults on
running, on the socket call which is worrying.
here's my code:

#include <unistd.h>
#include <sys/types.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <sys/socket.h>

#define MYPORT 3592

int main()
{
    int sockfd;
    int newsock;
    int len;
    char buf[256];
    struct sockaddr_in my_addr;
    struct sockaddr_in peer_in;
    printf("about to call socket\n");
    sockfd = socket(AF_INET, SOCK_STREAM, 0);
    if(sockfd == -1)
    {
        printf("sockfd = erro\n");
        exit(1);
    }
    my_addr.sin_family = AF_INET; /*host byte order */
    my_addr.sin_port = htons(MYPORT); /* short network byte order*/
    my_addr.sin_addr.s_addr = inet_addr("127.0.0.1");
    bzero(&(my_addr.sin_zero), 8); /* zero the rest */
    
    bind(sockfd, (struct sockaddr *)&my_addr, sizeof(struct sockaddr));
    
    listen ( sockfd, 5 );
    
    for (;;) {
 	len = sizeof ( struct sockaddr_in );

    newsock = accept ( sockfd, (struct sockaddr *)&peer_in, &len );

    recv ( newsock, buf, 256, 0 );
    send ( newsock, "hello", 256, 0 );

    printf ("From %s: %s\n", inet_ntoa ( peer_in.sin_addr ), buf );

    close ( newsock );
    
    }
    return 0;
}

is there a problem with ym code or my setup or can
someone who has tried a bit of socket programming with rsxntdj
give me any advidce?

Thanks in advance

Ed Hill

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019