Sponsored Content
Full Discussion: inet_pton question
Top Forums Programming inet_pton question Post 302212593 by konvalo on Tuesday 8th of July 2008 01:39:40 AM
Old 07-08-2008
Question inet_pton question

I use FreeBSD5.3,I use inet_pton under c language,like follows:
if(inet_pton(AF_INET6,argv[1],&servaddr.sin6_addr)<=0){
printf("error");
}
else{
printf("ok");
}

Then I run above code,
./a.out 127.0.0.1

It shows "error"! I don't know why it don't show "ok",anyone could tell me the reason and how to do it?

Thanks in advance!
Best regards,
konvalo
 

9 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Next Question:

what is the function of swap in linux why i have to create apsolutely a particion for the swap when i install (i installed lnx4win mandrake and made an automat. disk particion and the install program one of my disk partitions that was 3gb devidet in 4 one native 700mb swap 600mb and the others i... (1 Reply)
Discussion started by: user666
1 Replies

2. UNIX for Dummies Questions & Answers

cd-r vs. cd-rw question

I'm trying to put together a script that will burn some data to a cd....is there a way to tell from the command line whether the cd in the drive is a cd-r or a cd-rw? I'd like to blank the cd 1st if it's a cd-rw, but I want to automate this instead of asking for user input. Thanks!! (4 Replies)
Discussion started by: jalburger
4 Replies

3. Programming

inet_pton function

Hello, First of all: please pardon my inexperience. I'm new to Unix/Linux. My apologies upfront :) I'm trying to use the inet_pton() function. I've created the below script based on what I found in the manual (man inet_pton): #include <sys/types.h> #include <sys/socket.h> #include... (4 Replies)
Discussion started by: zheng
4 Replies

4. UNIX for Dummies Questions & Answers

A question?

using my unix os, can i do any autoexec.bat editing in order to execute selected programs that i use most often? :confused: (1 Reply)
Discussion started by: alecks1975
1 Replies

5. UNIX for Dummies Questions & Answers

a question

I was experimenting with redirection. Manual says >&digit --> standard output is redirected to the file descriptor digit I tried exec 3>myout exec >&3 This sent all the output to myout. Nothing was coming on the screen. I was thinking duplication will result in output similar to what... (7 Replies)
Discussion started by: ranj@chn
7 Replies

6. UNIX for Dummies Questions & Answers

I/O question

Hi, I have a simple .ksh file that list the contents of a folder. The contents of the folder need to be checked (make sure they are there). I have the output printed to a log. I then FTP to a windows server where the log is read. The problem is when I read the log file in windows there are... (1 Reply)
Discussion started by: bonekrusher
1 Replies

7. Shell Programming and Scripting

Another question regarding yes

I have a program that takes two responses, for example: ./eatfruit <stdout> Enter fruit: Do you want to eat fruit?: <end stdout> If I do this yes banana ./eatfruit <stdout> Enter fruit: banana (2 Replies)
Discussion started by: nj78
2 Replies

8. UNIX for Dummies Questions & Answers

Help me these Question??

1. How the Unix system identify the Other User to access for file permission? 2. What command we use to convert the extension of a file name? 3. What command use to convert other editing file to Unix based text file? Please answer of these Question???Its necessary for me?? (3 Replies)
Discussion started by: pradipta_pks
3 Replies

9. UNIX for Dummies Questions & Answers

Question about $*

Hi, I have shell scrit code like below, but I have need few clarification on this. I have explained my understanding and doubts after this code. abcd() { print $(date +%y%m%d:%H%M%S) "$*" } exec >> /root/file1.log 2>&1 My understanding is abcd() is a function it... (3 Replies)
Discussion started by: stew
3 Replies
INET_PTON(3)						     Linux Programmer's Manual						      INET_PTON(3)

NAME
inet_pton - convert IPv4 and IPv6 addresses from text to binary form SYNOPSIS
#include <arpa/inet.h> int inet_pton(int af, const char *src, void *dst); DESCRIPTION
This function converts the character string src into a network address structure in the af address family, then copies the network address structure to dst. The af argument must be either AF_INET or AF_INET6. The following address families are currently supported: AF_INET src points to a character string containing an IPv4 network address in dotted-decimal format, "ddd.ddd.ddd.ddd", where ddd is a dec- imal number of up to three digits in the range 0 to 255. The address is converted to a struct in_addr and copied to dst, which must be sizeof(struct in_addr) (4) bytes (32 bits) long. AF_INET6 src points to a character string containing an IPv6 network address. The address is converted to a struct in6_addr and copied to dst, which must be sizeof(struct in6_addr) (16) bytes (128 bits) long. The allowed formats for IPv6 addresses follow these rules: 1. The preferred format is x:x:x:x:x:x:x:x. This form consists of eight hexadecimal numbers, each of which expresses a 16-bit value (i.e., each x can be up to 4 hex digits). 2. A series of contiguous zero values in the preferred format can be abbreviated to ::. Only one instance of :: can occur in an address. For example, the loopback address 0:0:0:0:0:0:0:1 can be abbreviated as ::1. The wildcard address, consisting of all zeros, can be written as ::. 3. An alternate format is useful for expressing IPv4-mapped IPv6 addresses. This form is written as x:x:x:x:x:x:d.d.d.d, where the six leading xs are hexadecimal values that define the six most-significant 16-bit pieces of the address (i.e., 96 bits), and the ds express a value in dotted-decimal notation that defines the least significant 32 bits of the address. An example of such an address is ::FFFF:204.152.189.116. See RFC 2373 for further details on the representation of IPv6 addresses. RETURN VALUE
inet_pton() returns 1 on success (network address was successfully converted). 0 is returned if src does not contain a character string representing a valid network address in the specified address family. If af does not contain a valid address family, -1 is returned and errno is set to EAFNOSUPPORT. CONFORMING TO
POSIX.1-2001. NOTES
Unlike inet_aton(3) and inet_addr(3), inet_pton() supports IPv6 addresses. On the other hand, inet_pton() accepts only IPv4 addresses in dotted-decimal notation, whereas inet_aton(3) and inet_addr(3) allow the more general numbers-and-dots notation (hexadecimal and octal num- ber formats, and formats that don't require all four bytes to be explicitly written). For an interface that handles both IPv6 addresses, and IPv4 addresses in numbers-and-dots notation, see getaddrinfo(3). BUGS
AF_INET6 does not recognize IPv4 addresses. An explicit IPv4-mapped IPv6 address must be supplied in src instead. EXAMPLE
The program below demonstrates the use of inet_pton() and inet_ntop(3). Here are some example runs: $ ./a.out i6 0:0:0:0:0:0:0:0 :: $ ./a.out i6 1:0:0:0:0:0:0:8 1::8 $ ./a.out i6 0:0:0:0:0:FFFF:204.152.189.116 ::ffff:204.152.189.116 Program source #include <arpa/inet.h> #include <stdio.h> #include <stdlib.h> #include <string.h> int main(int argc, char *argv[]) { unsigned char buf[sizeof(struct in6_addr)]; int domain, s; char str[INET6_ADDRSTRLEN]; if (argc != 3) { fprintf(stderr, "Usage: %s {i4|i6|<num>} string ", argv[0]); exit(EXIT_FAILURE); } domain = (strcmp(argv[1], "i4") == 0) ? AF_INET : (strcmp(argv[1], "i6") == 0) ? AF_INET6 : atoi(argv[1]); s = inet_pton(domain, argv[2], buf); if (s <= 0) { if (s == 0) fprintf(stderr, "Not in presentation format"); else perror("inet_pton"); exit(EXIT_FAILURE); } if (inet_ntop(domain, buf, str, INET6_ADDRSTRLEN) == NULL) { perror("inet_ntop"); exit(EXIT_FAILURE); } printf("%s ", str); exit(EXIT_SUCCESS); } SEE ALSO
getaddrinfo(3), inet(3), inet_ntop(3) COLOPHON
This page is part of release 3.53 of the Linux man-pages project. A description of the project, and information about reporting bugs, can be found at http://www.kernel.org/doc/man-pages/. Linux 2008-06-18 INET_PTON(3)
All times are GMT -4. The time now is 05:55 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy