Socket Connection to an IP Address
Article Metadata
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);
sockfd = socket(AF_INET,SOCK_DGRAM,IPPROTO_UDP);
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);
//Binding
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);
close(sockfd);
return;
}
Links
Reading AP(Access Point) Table


24 Sep
2009
Article shows the how to connect ip address with access point. It’s a common thing for all online or internet application. As its a common, but it also a very grand thing in mobile world. Without a socket connection mobile-web applications are nothing. no improvement needed in this article. link of some another article is also a good thing in this article.