DaemonForums  

Go Back   DaemonForums > OpenBSD > OpenBSD General

OpenBSD General Other questions regarding OpenBSD which do not fit in any of the categories below.

Reply
 
Thread Tools Display Modes
  #1   (View Single Post)  
Old 3rd June 2009
SunSpyda SunSpyda is offline
Port Guard
 
Join Date: Mar 2009
Posts: 20
Thanked 0 Times in 0 Posts
Question netinet/in.h in OpenBSD 4.4 i386 broken?

I'm trying to get socket programming to work, but it just won't do it. I've tried the same code on Linux and other *nix OSes, and it worked fine, but it just refuses to work on OpenBSD...

The faults occur within that header file. Let's take this *really* simple C code...

Code:
#include <netinet/in.h>
#include <stdio.h>
#include <sys/socket.h>

#define PORT 13

int main( void )
{
    int socket = socket( AF_INET, SOCK_STREAM, 0 );
    struct sockaddr_in address;

    address.sin_family = AF_INET;
    address.sin_port = PORT;

    puts( "\nInitialization complete.\n" );

    return 0;
}
As I said, this code works great on other *nix OSes, but not OpenBSD. It just chokes when processing the netinet/in.h file. Any ideas?

I'm using GCC by the way.
Reply With Quote
  #2   (View Single Post)  
Old 3rd June 2009
BSDfan666 BSDfan666 is offline
Real Name: N/A, this is the interweb.
Helpful companion
 
Join Date: Apr 2008
Location: Ontario, Canada
Posts: 2,223
Thanked 193 Times in 184 Posts
Default

I hardly believe that this compiles anywhere, for one..
  • You're naming your local variable socket.. it clashes with the name of the socket function.
  • You populate a few elements of the sockaddr_in structure, but don't do anything with it.
Code:
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>

#define PORT 13

int main( void )
{
    int sock = socket( AF_INET, SOCK_STREAM, 0 );
    struct sockaddr_in address;

    address.sin_family = AF_INET;
    address.sin_port = PORT;

    puts( "\nInitialization complete.\n" );

    return 0;
}
It should at least compile now, but it's not exactly doing much of anything...

Helpful links:
http://beej.us/guide/bgnet/
Reply With Quote
  #3   (View Single Post)  
Old 3rd June 2009
SunSpyda SunSpyda is offline
Port Guard
 
Join Date: Mar 2009
Posts: 20
Thanked 0 Times in 0 Posts
Default

Quote:
Originally Posted by BSDfan666 View Post
You're naming your local variable socket.. it clashes with the name of the socket function.
Yeah, a stupid mistake on my behalf.. They should really be called server_fd on a server app, right?

Quote:
Originally Posted by BSDfan666 View Post
[*]You populate a few elements of the sockaddr_in structure, but don't do anything with it.
I know that structs utterly pointless, as it isn't being used, but it shouldn't generate an error should it?

Hmmm, this still won't compile...

Code:
#include <netinet/in.h>
#include <stdio.h>
#include <sys/socket.h>
#include <sys/types>

#define PORT 13

int main( void )
{
    int sock = socket( AF_INET, SOCK_STREAM, 0 );
    struct sockaddr_in address;

    address.sin_family = AF_INET;
    address.sin_port = PORT;

    puts( "\nInitialization complete.\n" );

    return 0;
}
Reply With Quote
  #4   (View Single Post)  
Old 3rd June 2009
ephemera's Avatar
ephemera ephemera is offline
Knuth's homeboy
 
Join Date: Apr 2008
Posts: 537
Thanked 49 Times in 43 Posts
Default

move sys/types.h before both sys/socket.h and netinet/in.h
Reply With Quote
  #5   (View Single Post)  
Old 3rd June 2009
SunSpyda SunSpyda is offline
Port Guard
 
Join Date: Mar 2009
Posts: 20
Thanked 0 Times in 0 Posts
Default

Thanks a lot! That solved nearly all the issues I was having. Furthermore, I completely forgot that the ordering of the includes makes a difference, so thanks for reminding me
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
OpenBSD 4.6 i386 boot hangs with old gateway system - resolved comet--berkeley OpenBSD Installation and Upgrading 6 22nd July 2011 08:15 AM
openbsd 4.5 macppc radeon drive still broken gosha OpenBSD Installation and Upgrading 13 28th June 2009 03:14 PM
openbsd 4.3 e2fsprogs seems to be broken gosha OpenBSD Packages and Ports 0 27th June 2009 03:18 AM
WindowMaker 0.92.0p7 (OpenBSD 4.4/i386 Packages) configuration issue. xixobrax OpenBSD General 1 3rd May 2009 04:04 PM
OpenBSD 4.4/4.5 i386 installation on Dell Inspiron 6400 notebook. xixobrax OpenBSD Installation and Upgrading 12 30th April 2009 04:34 AM


All times are GMT. The time now is 03:54 AM.


Powered by vBulletin® Version 3.8.4
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Content copyright © 2007-2010, the authors
Daemon image copyright ©1988, Marshall Kirk McKusick