473,385 Members | 1,357 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

connecting to a modem using winsock

Hi all,

There are two questions

1. I am trying to write a programme which can query to a modem get the modem details. i am using normal send() and recv() functions. But when i try to fetch a file from the modem. It shows me...

Error:400 Bad request.

2. The modem requires a username and password to get inside it. How can i set the username and password into it?

Here goes my code..

I hope my approach is correct. May be the way i am doing it is wrong.

#include <winsock2.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include<conio.h>

#define DEFAULT_PORT 80

#define DEFAULT_PROTOCOL SOCK_STREAM // TCP
#define PRINTERROR(s) \
fprintf(stderr,"\n%: %d\n", s, WSAGetLastError())

int main(void)
{
WSADATA wsaData;
SOCKET conn_socket;
struct sockaddr_in server;
struct hostent *hp;
char *server_name = "192.168.1.1";// modem IP address
unsigned short port = DEFAULT_PORT;
unsigned int addr = 0;
int socket_type = DEFAULT_PROTOCOL;
int retval = 0;
int loopflag = 0;
int loopcount = 0;
int maxloop = -1;
int i = 0;
char szBuffer[1024];
int nRet;


FILE *fp = fopen("read.txt","w");

if( WSAStartup(0x202,&wsaData) == SOCKET_ERROR )
{
fprintf(stderr,"WSAStartup failed with error %d\n",WSAGetLastError());
WSACleanup();
return -1;
}


if( isalpha(server_name[0]) )
{
hp = gethostbyname(server_name);
}
else
{
addr = inet_addr(server_name);
hp = gethostbyaddr((char *)&addr,4,AF_INET);
}


if( hp == NULL )
{
fprintf(stderr,"Client: Cannot resolve address [%s]: Error %d\n",
server_name,WSAGetLastError());
WSACleanup();
exit(1);
}

memset(&server,0,sizeof(server));
memcpy(&(server.sin_addr),hp->h_addr,hp->h_length);
server.sin_family = hp->h_addrtype;
server.sin_port = htons(port);

conn_socket = socket(AF_INET,socket_type,0); /* Open a socket*/

if( conn_socket < 0 )
{
fprintf(stderr,"Client: Error Opening socket: Error %d\n",
WSAGetLastError());
WSACleanup();
return -1;
}


printf("Client connecting to: %s\n",hp->h_name);

if(connect(conn_socket,(struct sockaddr*)&server,sizeof(server)) == SOCKET_ERROR)
{
fprintf(stderr,"connect() failed: %d\n",WSAGetLastError());
fprintf(stderr,"Server not found...\n\n");
WSACleanup();
return -1;
}

/* Trying to get data from the modem*/

sprintf(szBuffer, "GET %s\n","/cgi-bin/webcm.html\n","\n");

nRet = send(conn_socket, szBuffer, strlen(szBuffer), 0);
if (nRet == SOCKET_ERROR)
{
PRINTERROR("send()");
closesocket(conn_socket);
}

while(1)
{
nRet = recv(conn_socket, szBuffer, sizeof(szBuffer), 0);
if (nRet == SOCKET_ERROR)
{
PRINTERROR("recv()");
break;
}

if (nRet == 0)
break;
fwrite(szBuffer, nRet, 1,fp);

}
closesocket(conn_socket);
fclose(fp);
return 0;
}

Anybody has any idea how to proceed. Please help. Sorry if there are any spelling mistakes.

Thanks in advance
Feb 2 '07 #1
0 1996

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Ashish | last post by:
Hi, I was trying to make a out going call through the voice modem, play a audio file and disconnect. With the XTAPI implementation of the JTAPI I am able to do it with an analog phone line. The...
3
by: chethana | last post by:
I am using copmaq ipaq pocket pc 2002 h3600 series. This device is synchronized with desk top pc running on windows 2000. I want this pocket pc to be conncted to internet .Kindly help ...
5
by: kc | last post by:
Hi Just upgrading a app from VB6 to VB.Net. All is going well apart from the Winsock control. The first thing we notice is that there does not appear to be a .Net version (please correct me if...
17
by: Franc Zabkar | last post by:
My D-Link DSL-302G modem/router has a real-time clock whose settings are volatile. To avoid hand keying the date/time via the modem's JS interface, I wonder if there is a way to copy the JS code to...
1
by: Nicolas Ghesquiere | last post by:
Hello I have a problem with my current program. The meaning of the program is to allow users to login to a server to allow them to access the internet. My program communicates with a MS isa...
38
by: hkarthik | last post by:
hi, I am doing a project regarding SMS and i am doing it in ASP.NET. My project actually aims at sending message from my PC to mobile and then getting back the reply from the mobile to my pc. I...
9
by: darthghandi | last post by:
I am trying to create a server application using asynchronous sockets. I run into a problem when I try to connect to my server using a non-.net program. I can establish the connection, and send...
1
by: ElvisRS | last post by:
Hi, I'm writing a simple udp client using sockets. My code looks like this: initServer2 = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp);...
4
by: saintme | last post by:
Hello all, I have a USB modem stick and a PoE network device. I want to connect the device to the Internet using the USB stick. The device has no other interfaces, so I must use its RJ-45 port. I...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.