• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Fwd: Bsd sockets and GCC 4.0
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Fwd: Bsd sockets and GCC 4.0


  • Subject: Fwd: Bsd sockets and GCC 4.0
  • From: Jonas Maebe <email@hidden>
  • Date: Thu, 19 May 2005 11:36:11 +0200

I guess this was intended for the list.


Begin forwarded message:

From: Ryan Lum <email@hidden>
Date: 17 mei 2005 00:52:20 GMT+02:00
To: Jonas Maebe <email@hidden>
Subject: Re: Bsd sockets and GCC 4.0

On 5/16/05 4:47 PM, "Jonas Maebe" <email@hidden> wrote:

Thanks for all your help, I actually just typoed the code I posted. Sorry.
Here is the whole function. I am not interested in the DIKU_WINDOWS code.


I did try a different ver though

int co1800_init_socket(int port)
{
    int s, opt;
    struct sockaddr_in sa;
    struct linger ld;
        char buf[MAX_STRING_LENGTH];


#if defined (DIKU_WINDOWS) WORD wVersionRequested; WSADATA wsaData;

    wVersionRequested = MAKEWORD(2, 0);

    if (WSAStartup(wVersionRequested, &wsaData) != 0) {
    main_log("SYSERR: WinSock not available!");
    exit(1);
    }


if ((s = socket(PF_INET, SOCK_STREAM, 0)) == INVALID_SOCKET) {
sprintf (buf, "SYSERR: Error opening network connection: Winsock
error #%d", WSAGetLastError());
main_log(buf);
exit(1);
}


#endif

    GVLOCATION(3130);

    memset(&sa, 0, sizeof(struct sockaddr_in));
#if defined (DIKU_WINDOWS)
    sa.sin_family = PF_INET;
    sa.sin_port = htons((unsigned short)port);
#else
    sa.sin_family = AF_INET;
    sa.sin_port = htons(port);

#endif
    if ((s = socket(AF_INET, SOCK_STREAM, 0)) < 0) {
             bzero(buf, sizeof(buf));
             sprintf(buf, "ERROR: opening socket.\r\n");
             perror(buf);
             ABORT_PROGRAM();
    }

opt = 1;
if (setsockopt(s, SOL_SOCKET, SO_REUSEADDR, (char *) &opt, sizeof(opt))
< 0) {
main_log ("ERROR: Socket error (comm.c)");
spec_log("ERROR: Socket error (comm.c)", ERROR_LOG);
exit(1);
}
ld.l_onoff = 0; /* make sure this is on */
ld.l_linger = 1000; /* who cares about this */


if (setsockopt(s, SOL_SOCKET, SO_LINGER, (char *)&ld, sizeof(ld)) <0) {
main_log ("ERROR: ANother socker error (comm.c)");
spec_log("ERROR: ANother Socket error (comm.c)", ERROR_LOG);
exit(1);
}


GVLOCATION(3135);
int tempI;
tempI= bind(s, (struct sockaddr *)&sa, sizeof(sa));
if ( tempI < 0) {
long ct;
#if defined (DIKU_WINDOWS)
if (closesocket(s))
#else
if(close(s))
#endif
fprintf(stderr, "co1800_init_socket: error closing socket: %d",
errno);
ct = time(0); /* since script loops wait around a bit */
while (time(0)-45 < ct) {


            if (ct > time(0)) ct = time(0);
        }
        sprintf (buf, "%d", tempI);
        printf("error %d on socketpair\n", errno);
        main_log(buf);
        main_log ("ERROR: Damn socket errors (comm.c)");
        spec_log("ERROR: Damn socket errors (comm.c)", ERROR_LOG);
        exit(1);
    }
    if (listen(s, 5) < 0) {
        main_log ("ERROR: sigh (comm.c) bug #: 3174517521297519275");
        spec_log("ERROR: sigh (comm.c) bug #: 3174517521297519275",
ERROR_LOG);
        exit(1);
    }
    return(s);
}


Output:

error 48 on socketpair (errno)
Mon May 16 17:46:04 2005 :: -1 (tempI)

Mon May 16 17:46:04 2005 :: ERROR: Damn socket errors (comm.c)


dmdevel has exited with status 1.



I don't have time right now to read the man bind text or google for the
socketpair error, but I imagine it will probably help fix the error. Can
anyone recommend a good book that covers bsd sockets. I imagine I will have
to actually read about sockets before I figure this out.



On 16 May 2005, at 23:39, Ryan Lum wrote:

if(bind(s, (struct sockaddr *)&sa, sizeof(sa) < 0)) {

With gcc 3.3 no problems, but it is returning -1 with 4.0.  I am no
socket
expert, and any debugging advice would help.

Your code has been wrong for 10 years, it should be

if(bind(s, (struct sockaddr *)&sa, sizeof(sa)) < 0) {

You were passing 0 as namelen parameter (since sizeof(sa) > 0). Not
sure why this would work with gcc 3 and not with 4 though.


Jonas _______________________________________________ Do not post admin requests to the list. They will be ignored. Darwin-dev mailing list (email@hidden) Help/Unsubscribe/Update your Subscription: This email sent to email@hidden



_______________________________________________ Do not post admin requests to the list. They will be ignored. Darwin-dev mailing list (email@hidden) Help/Unsubscribe/Update your Subscription: This email sent to email@hidden
  • Follow-Ups:
    • Re: Bsd sockets and GCC 4.0
      • From: Justin Walker <email@hidden>
    • Re: Bsd sockets and GCC 4.0
      • From: plumber <email@hidden>
  • Prev by Date: Re: passwordserver_sasl-59.2
  • Next by Date: Re: Bsd sockets and GCC 4.0
  • Previous by thread: Re: Bsd sockets and GCC 4.0
  • Next by thread: Re: Bsd sockets and GCC 4.0
  • Index(es):
    • Date
    • Thread