LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 07-07-2017, 08:34 AM   #1
JHugh
Member
 
Registered: Jul 2017
Posts: 33

Rep: Reputation: Disabled
Question C code - IPv6 programming question


Background:
This is a C code for Linux question, so do not run when you see a different language plz.

I am working in the LabVIEW environment on a sbRIO running Linux. I am trying to program IPv6 communication using C code for Linux.


Question:
The problem that I am currently having is finding the correct integers not constants to put into the various commands socket, bind etc... All of the examples on the web show constants instead of the actual integer value which I need.

How/where can I find these integer values?


What I Tried:
I thought it might be in the header file, so I downloaded Cygwin and searched it for socket.h. I found it.

After reading through socket.h from my Cygwin directory, I managed to find the numeric value for AF_INET6. Using the int socket(int domain, int type, int protocol) gives me an error if I use:

domain = 23; // AF_INET6

type = 1; // SOCK_STREAM

protocol = 0; // DEFAULT


however, it works if I use:

domain = 10; // AF_CCITT

type = 1; // SOCK_STREAM

protocol = 0; // DEFAULT




Reference: http://man7.org/linux/man-pages/man2/socket.2.html


So how/where can I find these integer values and why is it not working when I put in the integer value for AF_INET6? Do different compilers/versions of Linux have different header files?

Thanks.
 
Old 07-07-2017, 09:36 AM   #2
NevemTeve
Senior Member
 
Registered: Oct 2011
Location: Budapest
Distribution: Debian/GNU/Linux, AIX
Posts: 4,862
Blog Entries: 1

Rep: Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869
Please provide a complete minimal working example program, that demonstrates the problem.
 
Old 07-07-2017, 10:50 AM   #3
rtmistler
Moderator
 
Registered: Mar 2011
Location: USA
Distribution: MINT Debian, Angstrom, SUSE, Ubuntu, Debian
Posts: 9,882
Blog Entries: 13

Rep: Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930
Because AF_INET6 is supposed to be 10.
 
Old 07-07-2017, 11:35 AM   #4
JHugh
Member
 
Registered: Jul 2017
Posts: 33

Original Poster
Rep: Reputation: Disabled
So, I managed to find the socket.h header file that defines some of these values. In the file AF_INET6 = 10 and SOCK_STREAM = 1.

Now I need to test the bind command whose syntax is:

Code:
     
struct sockaddr_in6 {
      sa_family_t     sin6_family;   /* AF_INET6 */
      in_port_t       sin6_port;     /* port number */
      uint32_t        sin6_flowinfo; /* IPv6 flow information */
      struct in6_addr sin6_addr;     /* IPv6 address */
      uint32_t        sin6_scope_id; /* Scope ID (new in 2.4) */
};

struct in6_addr {
      unsigned char   s6_addr[16];   /* IPv6 address */
};

Reference: http://man7.org/linux/man-pages/man2/bind.2.html


I know how to define: sin6_family = 10

I assume that I can define sin6_port = 3333 (arbitrary number between 1024 and 5000)

I also assume that s6_addr = "0000000000000001" since we only have 16 char available. Is this assumption correct?

What is sin6_flowinfo and sin6_scope_id and how should I define them?

Thanks.
 
Old 07-07-2017, 12:01 PM   #5
NevemTeve
Senior Member
 
Registered: Oct 2011
Location: Budapest
Distribution: Debian/GNU/Linux, AIX
Posts: 4,862
Blog Entries: 1

Rep: Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869
Don't worry about them; use memset to clear the whole structure, then set the family and the port -- don't forget using htons(3) with the latter.

Last edited by NevemTeve; 07-07-2017 at 12:04 PM.
 
Old 07-07-2017, 12:29 PM   #6
rtmistler
Moderator
 
Registered: Mar 2011
Location: USA
Distribution: MINT Debian, Angstrom, SUSE, Ubuntu, Debian
Posts: 9,882
Blog Entries: 13

Rep: Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930
I was thinking similar to NevemTeve. To clear the whole structure and to me, back when all these values were still jelling across multiple platforms, I just used the numbers, sans #define or enumerations. And did that long enough that eventually another programmer said "Hell-Lo!!! There are .H files!"
 
1 members found this post helpful.
Old 07-07-2017, 12:45 PM   #7
NevemTeve
Senior Member
 
Registered: Oct 2011
Location: Budapest
Distribution: Debian/GNU/Linux, AIX
Posts: 4,862
Blog Entries: 1

Rep: Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869
(Well, yes, all these header files are meant to be included, so we certainly don't have to manually define structures like sockaddr_in6.)
 
  


Reply



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 Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
IPv6 Programming mayankjohri Linux - Networking 0 03-16-2002 10:34 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 04:44 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration