Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Need a way to send a string to a Windows socket 1

Status
Not open for further replies.

cxnoel

Programmer
Nov 19, 2001
6
CA
Hi. I don't know much about Unix and I am not a C programmer. I need a little someting that can send a string to a remote machine using a socket channel. Is there any program that can be used for this which will accept a command like this: SendTo host port message

I found lot of C example using the Berkely Socket API but as I said, I am not a C programmer on Unix. I just need my Unix server be able to send a string on an already opened channel on my Windows NT server.

If anyone can help me, it will be greatly appreciated.

Thanks.
 
I wouldn't think you need C to do this. Try asking this question in the Perl forum: forum219, or in the Unix Scripting forum: forum822
 
its quite a simple prog in c but you need to understand a little C. In fact you don't need to code, you can telnet to your port and send you message, thats awful but should work.
tell me if you want some code in C.
 
Well, Telnet is not suitable for my needs. If you have a compiled C program (or any other language) that I can use by passing 3 parameters (host, port, message), it will be appreciated.

Thank you very much.
 
As rycamour said - Try asking this question in the Perl forum: Forum219, or in the Unix Scripting forum: Forum822 Mike
michael.j.lacey@ntlworld.com
Email welcome if you're in a hurry or something -- but post in tek-tips as well please, and I will post my reply here as well.
 
Can you send me a compiled program that I can use by using 3 parameters: host, port & message. Telnet is not suitable for my needs.

Thank you very much.
 
No, I'm sorry but I don't have time to write programs for you, that's why I suggested you ask your question in one of the scripting forums. Mike
michael.j.lacey@ntlworld.com
Email welcome if you're in a hurry or something -- but post in tek-tips as well please, and I will post my reply here as well.
 
copy everything under in toto.c then do a make toto. (please pay attention not to cut lines).



#include <stdio.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <netdb.h>
#include <unistd.h>
char *pname;
main(argc, argv)
int argc;
char *argv[];
{
int sockfd, c;
int port;
char *nom_ent;
struct hostent *hostptr;
struct sockaddr_in serv_addr;
struct in_addr *ptr;
pname = argv[0];
if (argc != 4) {
printf(&quot;_________________________________________________\n\n &quot;);
printf(&quot; Usage : %s hote port message \n\n&quot;, pname);
exit(0);
}
if ((hostptr = gethostbyname(argv[1])) == NULL) {
printf(&quot;Erreur : host %s non connu \n&quot;, argv[1]);
exit(1);
}
printf(&quot; Nom complet : %s \n&quot;, hostptr->h_name);
bzero((char *) &serv_addr, sizeof(serv_addr));
serv_addr.sin_family = AF_INET;
printf(&quot; Le serveur cible est : %s \n\n&quot;, argv[1]);
serv_addr.sin_addr.s_addr = inet_addr(argv[1]);
port = atoi(argv[2]);
printf(&quot; Le port cible est : %i \n\n&quot;, port);
serv_addr.sin_port = htons(port);
if ((sockfd = socket(AF_INET, SOCK_STREAM, 0)) < 0)
perror(&quot;client : Ouverture socket impossible &quot;);
if (connect(sockfd, (struct sockaddr *) & serv_addr, sizeof(serv_addr)) < 0) {
perror(&quot;client : connection au serveur impossible&quot;);
exit(1);
}
if (send(sockfd, argv[3], sizeof(argv[3]), 0) < 0)
perror(&quot;erreur d'ecriture&quot;);
shutdown(sockfd, 0);
exit(0);
}
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top