Serial Port Configuration


I'm trying to configure a serial port to be able to write to with or
without a device attached to it. If there is no device the data gets
dumped. Therefore I want raw I/O and no flow control of any kind, I
assume. Now, I've read the Serial Programming Howto and the Serial
Programming Guide for POSIX and I think I've got it right, but I must
be missing something. I have a small test pogram. After the data is
written to the serial port, tcdrain is called but it never returns,
just hangs there. I do not currently have anything attached to the
serial port and can only assume that nothing is being output (I'm a
little short of hardware currently). I've been hammering my head on
this for more than a day. So, what am I missing here?

#include <termios.h>
#include <stdio.h>
#include <string.h>
#include <fcntl.h>
#include <unistd.h>
#include <sys/ioctl.h>
#include <linux/serial.h>

#define PORT "/dev/ttyS2"

int main()
int fd, status;
char *msg ="Hello world!";
struct termios options;
struct serial_struct z_ser;

/* Open and configure the serial port */

memset( &options, 0, sizeof(options) );
options.c_cflag = B115200 | CS8 | CLOCAL | CREAD | IGNPAR;
options.c_oflag = 0;
options.c_lflag = 0;
options.c_iflag = INPCK | ISTRIP;
options.c_cc[VTIME] = 0;
options.c_cc[VMIN] = 1;
options.c_line = N_TTY;

if ( tcflush( fd, TCIOFLUSH ) < 0 )
printf("prob flush\n");

if( tcsetattr( fd, TCSANOW, &options) < 0 )
printf("prob set\n");

/* Write output */
if ( write( fd ,msg, strlen( msg ) ) < 0 )
printf("prob write\n");

/* Waiting until the output buffer is empty */
printf( "waiting to drain\n" );

tcdrain( fd ); /* tcdrain(fd) waits forever */

printf( "drained\n" );

/* Close the port */
close( fd );

Here's the port settings too (after running program):
speed 9600 baud; rows 0; columns 0; line = 0;
intr = <undef>; quit = <undef>; erase = <undef>; kill = <undef>; eof =
eol = <undef>; eol2 = <undef>; start = <undef>; stop = <undef>; susp =
rprnt = <undef>; werase = <undef>; lnext = <undef>; flush = <undef>;
min = 1; time = 0;
-parenb -parodd cs8 -hupcl -cstopb cread clocal -crtscts
-ignbrk -brkint -ignpar -parmrk inpck istrip -inlcr -igncr -icrnl -ixon
-iuclc -ixany -imaxbel -iutf8
-opost -olcuc -ocrnl -onlcr -onocr -onlret -ofill -ofdel nl0 cr0 tab0
bs0 vt0 ff0
-isig -icanon -iexten -echo -echoe -echok -echonl -noflsh -xcase
-tostop -echoprt
-echoctl -echoke