int main(int argc, char*argv[])
{
	int i,f;
	char *p;
	FILE *fp;
	char ** a;
	struct ifreq ifr;
	struct sockaddr_in*in;
	struct rtentry rt;
	char * dev = "lo";
	struct termios tty;
	int speed;

	open_raw_socket();

        setifaddr(dev, "127.0.0.1");
        setifflags(dev, IFF_UP | IFF_RUNNING | IFF_LOOPBACK);

        addroute(dev, RTF_UP/* | RTF_HOST*/,	
        	"127.0.0.0" /* dest net */,
        	"255.0.0.0" /* netmask */,
        	0 /* gateway */);
        
        close_raw_socket();
}
Exemple #2
0
int main() {
    const int port = 8000;
    http_server svc;

    //bring up tls machine, this need to be done before server setup
    int ng = tls_engine_inhale("server-cert.pem", "server-key.pem", 0);
    assert(ng == 0);

    setup_server(&svc, "0.0.0.0", port);

    //the length of path passed explicitly to stop strlen calling
    router *rtr = get_router(&svc);
    addroute(rtr, "/redfish", 8, write_res);

    printf("Listening on %d\n", port);

    //run forever
    run(&svc);

    tls_engine_stop();
    return 0;
}
Exemple #3
0
void route_command(const char *arg, struct session *ses)
{
    char a[BUFFER_SIZE], b[BUFFER_SIZE], way[BUFFER_SIZE], dist[BUFFER_SIZE], cond[BUFFER_SIZE];
    int j, d;

    arg=get_arg(arg, a, 0, ses);
    arg=get_arg(arg, b, 0, ses);
    arg=get_arg_in_braces(arg, way, 0);
    arg=get_arg(arg, dist, 0, ses);
    arg=get_arg_in_braces(arg, cond, 1);
    if (!*a)
    {
        tintin_printf(ses, "#THESE ROUTES HAVE BEEN DEFINED:");
        for (int i=0;i<MAX_LOCATIONS;i++)
            for (struct routenode *r=ses->routes[i];r;r=r->next)
                show_route(ses, i, r);
        return;
    }
    if (!*way)
    {
        bool first=true;
        if (!*b)
            strcpy(b, "*");
        for (int i=0;i<MAX_LOCATIONS;i++)
            if (ses->locations[i]&&match(a, ses->locations[i]))
                for (struct routenode *r=ses->routes[i];r;r=r->next)
                    if (ses->locations[i]&&
                          match(b, ses->locations[r->dest]))
                    {
                        if (first)
                        {
                            tintin_printf(ses, "#THESE ROUTES HAVE BEEN DEFINED:");
                            first=false;
                        }
                        show_route(ses, i, r);
                    }
        if (first)
            tintin_printf(ses, "#THAT ROUTE (%s) IS NOT DEFINED.", b);
        return;
    }
    int i;
    for (i=0;i<MAX_LOCATIONS;i++)
        if (ses->locations[i]&&!strcmp(ses->locations[i], a))
            goto found_i;
    if (i==MAX_LOCATIONS)
    {
        for (i=0;i<MAX_LOCATIONS;i++)
            if (!ses->locations[i])
            {
                ses->locations[i]=mystrdup(a);
                goto found_i;
            }
        tintin_eprintf(ses, "#TOO MANY LOCATIONS!");
        return;
    }
found_i:
    for (j=0;j<MAX_LOCATIONS;j++)
        if (ses->locations[j]&&!strcmp(ses->locations[j], b))
            goto found_j;
    if (j==MAX_LOCATIONS)
    {
        for (j=0;j<MAX_LOCATIONS;j++)
            if (!ses->locations[j])
            {
                ses->locations[j]=mystrdup(b);
                goto found_j;
            }
        tintin_eprintf(ses, "#TOO MANY LOCATIONS!");
        kill_unused_locations(ses);
        return;
    }
found_j:
    if (*dist)
    {
        char *err;
        d=strtol(dist, &err, 0);
        if (*err)
        {
            tintin_eprintf(ses, "#Hey! Route length has to be a number! Got {%s}.", arg);
            kill_unused_locations(ses);
            return;
        }
        if ((d<0)&&(ses->mesvar[MSG_ROUTE]||ses->mesvar[MSG_ERROR]))
            tintin_eprintf(ses, "#Error: distance cannot be negative!");
    }
    else
        d=DEFAULT_ROUTE_DISTANCE;
    addroute(ses, i, j, way, d, cond);
    if (ses->mesvar[MSG_ROUTE])
    {
        if (*cond)
            tintin_printf(ses, "#Ok. Way from {%s} to {%s} is now set to {%s} (distance=%i) condition:{%s}",
                ses->locations[i],
                ses->locations[j],
                way,
                d,
                cond);
        else
            tintin_printf(ses, "#Ok. Way from {%s} to {%s} is now set to {%s} (distance=%i)",
                ses->locations[i],
                ses->locations[j],
                way,
                d);
    }
    routnum++;
}