Please note that as of October 24, 2014, the Nokia Developer Wiki will no longer be accepting user contributions, including new entries, edits and comments, as we begin transitioning to our new home, in the Windows Phone Development Wiki. We plan to move over the majority of the existing entries. Thanks for all your past and future contributions.

Socket Connection to an IP Address

From Wiki
Jump to: navigation, search
Article Metadata
Created: spark55 (11 Sep 2007)
Last edited: hamishwillee (03 Feb 2012)

Following is the Open C code to connect to an IP Address given an Access Point name, IP Address and the port. This code uses ioctl to do the job. Similarly, we can do it even without using ioctl

int ConnectToIpAdress(char *apname, char *ipaddr , int port)
ifreq ifr;
int sockfd;
struct sockaddr_in destAddr, selfAddr;
// Name of the interface
strcpy(ifr.ifr_name, apname);
ioctl(sockfd,SIOCSIFNAME, &ifr);
ioctl(sockfd, SIOCIFSTART , &ifr);
selfAddr.sin_family = AF_INET;
selfAddr.sin_addr.s_addr = INADDR_ANY;
selfAddr.sin_port = htons(port);
bind(sockfd,(struct sockaddr*)&selfAddr, sizeof(selfAddr));
destAddr.sin_family = AF_INET;
destAddr.sin_addr.s_addr = inet_addr( ipaddr );
destAddr.sin_port = htons(port);
connect(sockfd, (struct sockaddr*)&destAddr, sizeof(destAddr));
ioctl(sockfd, SIOCIFSTOP, &ifr);


Reading AP(Access Point) Table

Start new Socket Connection to Access Point

Start new Socket Sub-connection to Access Point

This page was last modified on 3 February 2012, at 05:31.
34 page views in the last 30 days.