Skip to Content.
Sympa Menu

freetds - Re: via PHP to Microsoft SQL Server V7.0

freetds AT lists.ibiblio.org

Subject: FreeTDS Development Group

List archive

Chronological Thread  
  • From: Brian Bruns <camber AT umcc.ais.org>
  • To: TDS Development Group <freetds AT franklin.oit.unc.edu>
  • Subject: Re: via PHP to Microsoft SQL Server V7.0
  • Date: Thu, 20 Jan 2000 07:15:54 -0500 (EST)


I'll attach it here. You'll need to change IP/port before compiling,
enjoy!

Brian

On Thu, 20 Jan 2000, James Cameron wrote:

> Brian Bruns wrote:
> > Hmmm...from just doing some web searches it would seem that this would
> > work... (assuming of course it's actually domain\\username since the \
> > needs to be escaped in php).
>
> I've tried \\ too, and checked from TDSDUMP that it is propogated as \.
>
> Where's that pass-through server then?
>
> --
> James Cameron (cameron AT stl.dec.com)
>
> ---
> You are currently subscribed to freetds as: camber AT ais.org
> To unsubscribe, forward this message to $subst('Email.Unsub')
>
>
#include <stdio.h>
#include <sys/types.h>
#include <unistd.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <netdb.h>
#include <errno.h>

static void dump_buf(FILE *dumpfile, const void *buf, int length);
main()
{
struct sockaddr_in sin, sin2;
unsigned char buf[BUFSIZ];
int s, fd1, fd2;
int len, i;
fd_set rfds;
int retval;

sin.sin_addr.s_addr = INADDR_ANY;
sin.sin_port = htons(4000);
sin.sin_family = AF_INET;

if ((s = socket (AF_INET, SOCK_STREAM, 0)) < 0) {
perror ("socket");
exit (1);
}
if (bind (s, (struct sockaddr *) &sin, sizeof (sin)) < 0) {
perror("bind");
exit (1);
}
listen (s, 5);
if ((fd1 = accept (s, (struct sockaddr *) &sin, &len)) < 0) {
perror("accept");
exit(1);
}

sin2.sin_addr.s_addr = inet_addr("127.0.0.1");
sin2.sin_family = AF_INET;
sin2.sin_port = htons(4444);

if ((fd2 = socket (AF_INET, SOCK_STREAM, 0)) < 0) {
perror ("socket");
exit(1);
}

if (connect(fd2, (struct sockaddr *) &sin2, sizeof(sin2)) <0) {
perror("connect");
exit(1);
}

while (1) {
FD_ZERO(&rfds);
FD_SET(fd1, &rfds);
FD_SET(fd2, &rfds);

retval = select(fd2+1, &rfds, NULL, NULL, NULL);
if (FD_ISSET(fd1, &rfds)) {
len = read(fd1, buf, BUFSIZ);
if (len==0) {
fprintf(stdout,"Connection Closed by
Client\n");
close(fd1);
close(fd2);
exit(0);
} else {
fprintf(stdout,"Client to Server message\n");
dump_buf(stdout, buf, len);
write(fd2,buf,len);
}
}
if (FD_ISSET(fd2, &rfds)) {
len = read(fd2, buf, BUFSIZ);
if (len==0) {
fprintf(stdout,"Connection Closed by
Server\n");
close(fd1);
close(fd2);
exit(0);
} else {
fprintf(stdout,"Server to Client message\n");
dump_buf(stdout, buf, len);
write(fd1,buf,len);
}
}
}
}
static void dump_buf(
FILE *dumpfile,
const void *buf,
int length)
{
int i;
int j;
const int bytesPerLine = 16;
const unsigned char *data = buf;

for(i=0; i<length; i+=bytesPerLine) {

fprintf(dumpfile, "%04x ", i);

for(j=i; j<length && (j-i)<bytesPerLine; j++)
{
fprintf(dumpfile, "%02x ", data[j]);
}

for(; 0!=(j % bytesPerLine); j++)
{
fprintf(dumpfile, " ");
}
fprintf(dumpfile, " |");

for(j=i; j<length && (j-i)<bytesPerLine; j++)
{
fprintf(dumpfile, "%c", (isprint(data[j])) ? data[j] : '.');
}
fprintf(dumpfile, "|\n");
}
fprintf(dumpfile, "\n");
}




Archive powered by MHonArc 2.6.24.

Top of Page